package com.invite.me.ui.pay;

import android.content.Intent;
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.alipay.sdk.app.PayTask;

import com.invite.me.R;
import com.invite.me.base.BaseActivity;

import java.util.Map;

/***
 * 转出
 */
public class RolloutPreiceActivity extends BaseActivity implements View.OnClickListener {



    private static final int SDK_PAY_FLAG = 1;
    private static final int SDK_AUTH_FLAG = 2;
  //  public static final String RSA2_PRIVATE = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAndB7OaXytqb5N9q6UOnwDR539Au+0fZFWyPLLEQ9fQ7RtJEUBFu9/fFrhoYGN5KY/cRvQQfrPlq77IQwb80NleP4K2inY3GQr8pNY75jBw+ifbMX974Jt9742+zhythXjkAR7kAGfrPHU5UnhEa4I6QO6+TCqjoILWfHaagsSC36u7vKfEuIxNHPcQsumWV1dNV2gH0r1GFzmQPcQrabjCv7Gut7lfdyS9LY4sxAeb+KNwADb/MDwPZanz1DVsBgAFncSbIjwBhEkKlnxTd0ZcgRR6adttXSjkZWVCAeYB4n0dcQX6lhpH9VuBEKx8Je8yl2vXceR80m/3MBgN1prQIDAQAB";

    public static final String RSA2_PRIVATE="MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCd0Hs5pfK2pvk32rpQ6fANHnf0C77R9kVbI8ssRD19DtG0kRQEW7398WuGhgY3kpj9xG9BB+s+WrvshDBvzQ2V4/graKdjcZCvyk1jvmMHD6J9sxf3vgm33vjb7OHK2FeOQBHuQAZ+s8dTlSeERrgjpA7r5MKqOggtZ8dpqCxILfq7u8p8S4jE0c9xCy6ZZXV01XaAfSvUYXOZA9xCtpuMK/sa63uV93JL0tjizEB5v4o3AANv8wPA9lqfPUNWwGAAWdxJsiPAGESQqWfFN3RlyBFHpp221dKORlZUIB5gHifR1xBfqWGkf1W4EQrHwl7zKXa9dx5Hz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y4mrV31NWsQuXLuMv2evzNA/N6oU6AplnK5OWnBus5025ljKxulcHH5yQZkapNGMciA/UAWJCXmKE2Rr29iC0IcJ8Hx6Xcu8U2dGKuKSdfJw3cDD0S8Qtj6R+vYM5wjfargLoKi7xnrdGrnhzaQDAGTy1yOb91a7iY6lG1Sw=";

    private Handler mHandler = new Handler() {
        @SuppressWarnings("unused")
        public void handleMessage(Message msg) {
            switch (msg.what) {
                case SDK_PAY_FLAG: {
                    @SuppressWarnings("unchecked")
                    PayResult payResult = new PayResult((Map<String, String>) msg.obj);
                    /**
                     * 对于支付结果，请商户依赖服务端的异步通知结果。同步通知结果，仅作为支付结束的通知。
                     */
                    String resultInfo = payResult.getResult();// 同步返回需要验证的信息
                    String resultStatus = payResult.getResultStatus();
                    // 判断resultStatus 为9000则代表支付成功
                    if (TextUtils.equals(resultStatus, "9000")) {
                        // 该笔订单是否真实支付成功，需要依赖服务端的异步通知。
                        Log.e("dingdan", "该笔订单是否真实支付成功，需要依赖服务端的异步通知。" );
                    } else {
                        // 该笔订单真实的支付结果，需要依赖服务端的异步通知。
                        Log.e("dingdan", "该笔订单真实的支付结果，需要依赖服务端的异步通知。" );
                    }
                    break;
                }
//                case SDK_AUTH_FLAG: {
//                    @SuppressWarnings("unchecked")
//                    AuthResult authResult = new AuthResult((Map<String, String>) msg.obj, true);
//                    String resultStatus = authResult.getResultStatus();
//
//                    // 判断resultStatus 为“9000”且result_code
//                    // 为“200”则代表授权成功，具体状态码代表含义可参考授权接口文档
//                    if (TextUtils.equals(resultStatus, "9000") && TextUtils.equals(authResult.getResultCode(), "200")) {
//                        // 获取alipay_open_id，调支付时作为参数extern_token 的value
//                        // 传入，则支付账户为该授权账户
//                        showAlert(PayDemoActivity.this, getString(R.string.auth_success) + authResult);
//                    } else {
//                        // 其他状态值则为授权失败
//                        showAlert(PayDemoActivity.this, getString(R.string.auth_failed) + authResult);
//                    }
//                    break;
//                }
                default:
                    break;
            }
        };
    };
    @Override
    protected void initView() {
        ImageView imagefanhui = findViewById(R.id.imagefanhui);
        imagefanhui.setOnClickListener(this);

      TextView qurenzhuanchu= findViewById(R.id.qurenzhuanchu);
        LinearLayout zhifubaoxinxi= findViewById(R.id.zhifubaoxinxi);
        qurenzhuanchu.setOnClickListener(this);
        zhifubaoxinxi.setOnClickListener(this);

    }
    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.qurenzhuanchu:
//                Intent bdzf=new Intent(RolloutPreiceActivity.this, BindingZfbActivity.class);
//
//                startActivity(bdzf);
                boolean rsa2 = (RSA2_PRIVATE.length() > 0);
                Map<String, String> params = OrderInfoUtil2_0.buildOrderParamMap("2021000116671941", rsa2);
                String orderParam = OrderInfoUtil2_0.buildOrderParam(params);

                String privateKey = RSA2_PRIVATE;
                String sign = OrderInfoUtil2_0.getSign(params, privateKey, rsa2);
                final String orderInfo = orderParam + "&" + sign;
                Runnable payRunnable = new Runnable() {

                    @Override
                    public void run() {

                        PayTask alipay = new PayTask(RolloutPreiceActivity.this);
                        Map<String,String> result = alipay.payV2(orderInfo,true);

                        Message msg = new Message();
                        msg.what = SDK_PAY_FLAG;
                        msg.obj = result;
                        mHandler.sendMessage(msg);
                    }
                };
                // 必须异步调用
                Thread payThread = new Thread(payRunnable);
                payThread.start();


                break;
            case R.id.zhifubaoxinxi:
                Intent zhifubao=new Intent(RolloutPreiceActivity.this,ZhiFuBaoTypeActivity.class);

                startActivity(zhifubao);



                break;
            case R.id.imagefanhui:
                finish();

                break;

        }

    }
    @Override
    protected int getActivityLayoutId() {
        return R.layout.activity_rolloutpreice;
    }

    @Override
    protected void loadData() {

    }


}
